import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;

import javax.swing.JPanel;


public class Pong extends JPanel{
	
	public static final int XSIZE = 800;
	public static final int YSIZE = 600;
	
	public Player player = new Player(15, YSIZE / 2);
	public Computer computer = new Computer(XSIZE - 15, YSIZE / 2);
	
	public Ball ball = new Ball(XSIZE / 2, YSIZE / 2);
	
	public Pong()
	{
		this.setSize(XSIZE, YSIZE);
		this.setBackground(Color.WHITE);
		this.addKeyListener(player.input);
	}
	
	public void tick()
	{
		while(true)
		{
			
			player.tick();
			computer.tick();
			ball.tick();
			
			this.repaint();
			
			//System.out.println("Tick");
			
			try
			{
				Thread.sleep(20L);
			}catch(Exception e){}
		}
	}
	
	public void paintComponent(Graphics g)
	{
		
		g.setColor(Color.BLACK);
		g.fillRect(0, 0, XSIZE, YSIZE);
		
		player.render(g);
		computer.render(g);
		ball.render(g);
		
		/*for(int x = 0; x < XSIZE; x+=3)
		{
			for(int y = 0; y < YSIZE; y+=3)
			{
				g.setColor(new Color(new Random().nextInt(255), new Random().nextInt(255), new Random().nextInt(255)));
				g.fillRect(x, y, 3, 3);
			}
		}*/
	}
	
}
